home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
kernel.zip
/
K4.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-11-25
|
14KB
|
499 lines
;Listing 4 High Resolution Clock
;(C) Copyright 1986 Ken Berry.
;All rights reserved.
;Copies may be made for non-commercial, private use only.
;
include tele.mac ; system defintions (listing 2)
extrn t_syxtm:word ; system execution time accumulator
extrn sys_dgrp:word ; data segment storage
extrn sys_stat:word ; original register block
public t__tick ; system tick interrupt service
public t_astrm ; application task termination flag
public tmr_dspl ; physical display pointer
public tmr_dvsr ; timer period
public tmr_ilck ; tick service reentrant interlock
public tmr_sync ; synchronization function address
public tmr_tkct ; tick clock
public tmr_xtm ; tick service execution time
public tmr__clr ; reset time base generation
public tmr__int ; timer initialization function
public tmr__rst ; timer termination function
public tmr__sts ; read timer status
public tmr__tmr ; restart hardware timer
public t_rdclk ; read high resolution clock
public t_rtactg ; psuedo time accumulator pointer
public t_rtmark ; mark execution interval
public t__rdclk ; read real time clock
public td_ref ; clock update tick reference count
public td_tct ; clock tick timer
public td__set ; set time of day clock
public td__upd ; update time of day clock
public w__cdspl ; physical display update function
public w__sync ; physical display synchronization
RLCINT equ 80h ; relocated alternate time base interrupt
TMRINT equ 8 ; hardware timer interrupt
TMRPRT equ 40h ; timer (8253) port
TMRPRD equ 19912 ; timer period (60 Hz rate)
;TMRPRD equ 9956 ; timer period (120 Hz rate)
INTPRT equ 20h ; interrupt controller (8259) port
TMRMSK equ 01h ; hardware timer interrupt mask
INTEOI equ 20h ; interrupt termination value
DSPCT equ 1 ; 60 Hz interrupt rate
;DSPCT equ 2 ; 120 Hz interrupt rate
IDV0 equ 3 ; tmr_idv0 divisor
ISKP0 equ 776 ; tmr_ict correction value
ISKP1 equ 11 ; tmr_idv1 correction value
ISKP2 equ 38 ; tmr_idv2 correction value
dseg
tmr_tkct dw 0 ; interrupt counter
tmr_dct db 0 ; display counter
tmr_ict dw 0 ; tick clock (for time base generation)
tmr_dvsr dw TMRPRD ; 1/2 timer period
t_astrm db 0FFh ; application task termination flag
tmrflg db 0FFh ; system state flag (t__tick)
tmr_ilck db 0 ; tick service reentrant interlock
tmr_idv0 db 0 ; clock time base generator
tmr_idv1 db 0 ; primary alternate time base generator
tmr_idv2 db 0 ; secondary alternate time base generator
tmr_dspl dw 0 ; console display w_pwdw pointer
t_rtactg dw 0 ; psuedo time accumulator pointer
t_rtrfct dw 0 ; real time reference count
t_rttick dw 0 ; tick clock phase
tmr_xtm dw 3 dup (0) ; tick service psuedo time accumulator
tmrpxtm dw 0 ; prior psuedo time accumulator pointer
tmr_sync dw offset pgroup:w__sync ; synchronization function pointer
td_ref dw 0 ; clock update tick reference count
td_tct dw 0 ; clock tick timer
endds
pseg
;t__tick system tick service
;
;t__tick\\
;
;Control only comes here in response to an interrupt from the system clock.
;This function serves three purposes. It maintains the system clock, which
;provides the current date and time for both system and application uses. It
;also performs an update of the first physical display. And finally it
;terminates the execution interval for the current application task.
;
t__tick proc far
; reentrant lockout
assume ss:nothing,ds:nothing,es:nothing
sti ; interrupts on
push ds ; protect ds
push ax ; protect ax
mov ax,dgroup ; establish data addressability
mov ds,ax
assume ds:dgroup
mov al,INTEOI ; terminate interrupt
out INTPRT,al
ilck al,tmr_ilck ; test for not reentrant call
or al,al
jz tick
pop ax ; restore ax
pop ds ; restore ds
iret ; return from interrupt
; system interlock
tick: mov t_astrm,0FFh ; terminate application task
sys_entr tmrflg ; enter system state
; set machine environment
sys_sctx ; save processor context
push bp ; protect bp
mov bp,sp ; mark stack location
lea ax,tmr_xtm ; accumulate psuedo time
push ax
call t_rtmark
mov sp,bp
mov tmrpxtm,ax ; store prior pointer
; real time system processing
inc tmr_dct ; remove display harmonics
mov al,DSPCT
xor al,tmr_dct
jnz tick4
mov tmr_dct,al
push tmr_dspl ; display physical window
call w__cdspl
mov sp,bp ; restore stack pointer
inc tmr_ict ; increment interrupt counter
inc tmr_tkct ; increment tick clock
; time base generation
mov ax,ISKP0 ; long term time base correction
xor ax,tmr_ict
jnz tick1
mov tmr_ict,ax
call tick5 ; update system tick clock
tick1: inc tmr_idv0 ; generate clock time base
mov al,IDV0
xor al,tmr_idv0
jnz tick3
mov tmr_idv0,al
call tick5 ; update system tick clock
inc tmr_idv1 ; primary alternate time base correction
mov al,ISKP1
xor al,tmr_idv1
jnz tick2
mov tmr_idv1,al
int RLCINT ; update alternate time base
inc tmr_idv2 ; secondary alternate time base correction
mov al,ISKP2
xor al,tmr_idv2
jnz tick2
mov tmr_idv2,al
int RLCINT ; update alternate time base
tick2: int RLCINT ; update alternate time base
; terminate interrupt service
tick3: push tmrpxtm ; restore original psuedo time accumulator
call t_rtmark
mov sp,bp
pop bp ; restore bp
test tmrflg,0FFh ; test for interrupted system task
jnz tick4
xor ax,ax ; terminate task
mov tmr_ilck,al ; enable reentrance
retn ; near return to system task management
tick4: sys__rctx ; restore processor context
cli ; interrupts off
mov tmr_ilck,0 ; enable reentrance
pop ds ; restore ds
iret ; return to interrupted task
; update system tick counter
tick5: mov ax,td_tct ; test for no overflow
inc ax
cmp ax,td_ref
jne tick6
call td__upd ; update clock
xor ax,ax ; reset tick counter
mov td_ref,ax
mov td_tct,ax
tick6: inc td_tct ; increment tick counter
retn ; return
t__tick endp
;tmr__int initialize timer
;
;tmr__int()
;
;All data areas necessary for clock maintenance are initialized. The hardware
;timer is programmed for the appropriate rate and its interrupt vector is made
;to point to sys_tmr. The original vector is relocated and will be used by
;sys_tmr as the alternate time base.
;
tmr__int proc near
call tmr__dsi ; diable interrupts
mov ax,dgroup ; set data segment
mov sys_dgrp,ax
mov ax,cs ; set code segment
lea si,sys_stat
mov [si].rcs,ax
cli ; interrupts off
mov tmr_ilck,0FFh ; lockout t__tick
mov bx,tmr_sync ; test for no synchronization function
test bx,bx
jz int0
lea bx,tmr_sync ; synchronize timer interrupt
call [bx]
jmp short int1 ; continue
int0: call tmr__tmr ; start timer
int1: call t_rdclk ; set real time clock phase
mov t_rttick,ax
mov t_rtrfct,ax ; set reference count
mov t_rtactg,offset dgroup:t_syxtm ; initialize time accumulator
call td__set ; set current time
sti ; interrupts on
xor ax,ax ; form 0
push ds ; protect ds
mov ds,ax ; relocate original interrupt vector
mov di,ax
cli
mov ax,[di+4*TMRINT]
mov [di+4*RLCINT],ax
mov ax,[di+4*TMRINT+2]
mov [di+4*RLCINT+2],ax
mov ax,offset pgroup:t__tick ; set interrupt service
mov [di+4*TMRINT],ax
mov ax,cs
mov [di+4*TMRINT+2],ax
sti ; interrupts on
pop ds ; restore ds
call tmr__eni ; enable interrupts
ret ; return
tmr__int endp
;
;tmr__clr reset time base generation
;
;tmr__clr()
;
;The time base adjustment variables are reset. This function is to be called by
;td__set when the time of day is initially set from a continuous clock. Nothing
;is returned.
;
tmr__clr proc near
xor ax,ax ; zero time base generation variables
mov tmr_id